package com.roncoo.education.course.service.auth;

import javax.validation.constraints.NotNull;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.roncoo.education.common.config.ThreadContext;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.course.service.biz.ExperimentBiz;
import com.roncoo.education.course.service.biz.req.ExperimentReq;
import com.roncoo.education.course.service.biz.resp.ExperimentResp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * AUTH-实验信息
 *
 * @author wujing
 * @date 2023-07-24
 */
@Api(tags = "AUTH-实验信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/course/auth/experiment")
public class AuthExperimentController {

    @NotNull
    private final ExperimentBiz biz;

    /**
     * 实验详情接口
     */
    @ApiOperation(value = "实验详情", notes = "校验实验是否可以进行")
    @RequestMapping(value = "/view", method = RequestMethod.POST)
    public Result<ExperimentResp> view(@RequestBody ExperimentReq req, @RequestHeader("token") String token) {
//    	String token = request.getHeaders().getFirst(Constants.TOKEN);
        return biz.view(req, token, ThreadContext.userId());
    }
    
    /**
     * 实验详情接口
     */
    @ApiOperation(value = "用户实验关系", notes = "保存用户和实验的关系")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody ExperimentReq req) {
        return biz.save(req, ThreadContext.userId());
    }
    
    /**
     * 实验详情接口
     */
    @ApiOperation(value = "更新实验秘钥", notes = "保存用户和实验的关系")
    @RequestMapping(value = "/saveSecret", method = RequestMethod.POST)
    public Result saveSecret(@RequestBody ExperimentReq req) {
        return biz.saveSecret(req, ThreadContext.userId());
    }
}
